<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户登录</title>
    <script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-3.5.1.min.js"></script>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            margin: 0;
            padding: 20px;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
        }
        .container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        h3 {
            color: #333;
            text-align: center;
            margin-bottom: 20px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            color: #555;
        }
        input[type="text"] {
            width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
        }
        button {
            width: 100%;
            padding: 10px;
            background-color: #4CAF50;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
        }
        button:hover {
            background-color: #45a049;
        }
        #password {
        width: 100%;
            padding: 10px;
            margin-bottom: 15px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box;
    }
    #login {
    width: 100%;
    padding: 10px;
    background-color: #3498db; /* 蓝色 */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}
 
#login:hover {
    background-color: #2980b9; /* 悬停时的深蓝色 */
}


#register {
    width: 100%;
    padding: 10px;
    background-color: #4CAF50; /* 绿色 */
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}
 
#register:hover {
    background-color: #45a049; /* 悬停时的深绿色 */
}
    </style>
</head>
<body>
<div class="container">
    <h3>用户登录</h3>
    <div>
        <label>手机号</label>
        <div>
            <input type="text" placeholder="手机号" name="teiphon" id="teiphon">
        </div>
    </div>

    <div>
        <label>密码</label>
        <div>
            <input type="password" placeholder="login" name="password" id="password">
        </div>
    </div>

    <div>
        <button id="login" type="button" class="login">
            登录
        </button>
    </div>

    <div>
        <button id="register" type="button" class="register">
            注册
        </button>
    </div>

</div>
</body>
<script>
    jQuery(document).ready(function(){
        $("#register").on("click",function(){
            window.location.href="/miaoshaoqiangduan/getotp.html";
        });

       $("#login").on("click",function(){
       var teiphon=$("#teiphon").val();
       var password=$("#password").val();
       if(teiphon==null||teiphon==""){
       alert("手机号不能为空")
       return false;
       }

      if(password==null||password==""){
       alert("密码不能为空")
       return false;
       }

    

          $.ajax({
          type:"POST",
          contentType:"application/x-www-form-urlencoded",
          url:"http://localhost:8090/user/login",
          data:{
          "teiphon":$("#teiphon").val(),
          "password":password,

          },
          xhrFields: {
        withCredentials: true
    },
          success:function(data){
          if(data.status=="success"){
          alert("登录成功")
          window.location.href="/miaoshaoqiangduan/listitem.html"
          }else{
          alert("登录失败失败，原因为"+data.data.errMsg)
          }
          },
          error:function(data){
          alert("登录失败，原因为"+data.responseText);
          }
          });
          return false;
        });
    });
</script>